package ru.averta.notes.service.impl;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.Collection;
import java.util.List;

import net.sourceforge.safr.core.annotation.Filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;

import ru.averta.notes.dao.GenericDao;
import ru.averta.notes.domain.abstr.BusinessObject;
import ru.averta.notes.service.BusinessObjectService;
import ru.averta.notes.service.security.SecurityService;

@Transactional
public abstract class GenericBusinessObjectService<T extends BusinessObject, PK extends Serializable, D extends GenericDao<T, PK>> implements
BusinessObjectService<T, PK> {

	Logger logger = LoggerFactory.getLogger(GenericBusinessObjectService.class);

	private GenericDao<T, PK> dao;

	public T create(T newInstance) {
		dao.create(newInstance);
		return newInstance;
	}

	public T findByID(PK id) {
		return dao.findByID(id);
	}
	
	public Collection<T> findAll(Integer i) {
		return dao.findAll();
	}

	public void save(T transientObject) {
		dao.save(transientObject);
	}

	/*
	public void remove(PK id) {
		T object = dao.findByID(id);
		remove(object);
	}
	*/
	
	public void remove(T object) {
		dao.remove(object);
	}
	
	public abstract void setDao(D dao);
	
	protected void setGenericDao(GenericDao<T, PK> dao) {
		this.dao = dao;
	}

}
